import Head from "next/head";
import styles from "../styles/Home.module.css";
import Header from "../components/Header";
import MyList from "../components/List";
import { Affix } from "antd";
import { useState } from "react";
import axios from "axios";

const Knowledge = (props) => {
  const [top, setTop] = useState(0);
  const [list, setList] = useState(props.p.data);
  return (
    <div className={styles.container}>
      <Head>
        <title>blog</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <Affix offsetTop={top}>
        <Header />
      </Affix>
      <MyList list={list} />
    </div>
  );
};

export const getServerSideProps = async () => {
  const p = await new Promise((resolve) => {
    axios("http://127.0.0.1:7001/default/getKnowledge").then((res) => {
      resolve(res.data);
    });
  });
  return {
    props: {
      p,
    },
  };
};

export default Knowledge;
